// Learn TypeScript:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass{
    private cLoad=0;
    private loading:cc.Node;
    private wzNode:cc.Node;
    private txt:cc.Label;
    private g1:cc.Graphics;
    private r1:cc.Rect;
    private r2:cc.Rect;
    private startBo:boolean;
   public onLoad(){
        this.cLoad=0;

        this.loading=new cc.Node();
      
        let n=new cc.Node();
        n.parent=this.loading;

        this.wzNode=new cc.Node();
        this.txt=this.wzNode.addComponent(cc.Label);
        this.txt.string="";

        
       
        this.g1=n.addComponent(cc.Graphics);
        // this.n1= new cc.Node();
        // this.n1.parent=this.loading;
        this.r1=new cc.Rect();
        this.r2=new cc.Rect();
        // this.n2= new cc.Node();
        // this.n2.parent=this.loading;
        // this.g2=this.n2.addComponent(cc.Graphics());
        this.startBo=false;
        this.txt.fontSize=20;
    }
    private h=0;
    private bj=0;
    public onBJ(){
         this.h=this.bj;
    }
    public Init(){
        this.loading.x=cc.view.getVisibleOrigin().x;
        this.loading.y=cc.view.getVisibleOrigin().y;
    //    this.n2.x=cc.view.getVisibleOrigin().x;
    //    this.n2.y=cc.view.getVisibleOrigin().y+cc.view.getVisibleSize().height;
        this.startBo=true;
        this.g1.clear();
        this.bj=cc.view.getVisibleSize().height/2;
        this.h=this.bj;
        this.loading.parent=cc.Canvas.instance.node.parent;
      
        this.r1=new cc.Rect(cc.view.getVisibleOrigin().x,cc.view.getVisibleOrigin().y,cc.view.getVisibleSize().width,1);
        this.r2=new cc.Rect(cc.view.getVisibleOrigin().x,cc.view.getVisibleOrigin().y+cc.view.getVisibleSize().height,cc.view.getVisibleSize().width,1);
        
        
    }
    public onStart(){
        if(this.startBo){
            this.g1.clear();
            this.g1.fillColor=new cc.Color(0,0,0);
         
            if(this.h>=this.bj){
                this.startBo=false;
                this.wzNode.parent=this.loading;
                this.wzNode.x=cc.view.getVisibleOrigin().x+cc.view.getVisibleSize().width/2;
                this.wzNode.y=cc.view.getVisibleOrigin().y+cc.view.getVisibleSize().height/2;
                this.txt.string="正在加载素材";
              //  window.player.onMap();
        
            }else{
                this.h+=10;
            }
            this.g1.rect(cc.view.getVisibleOrigin().x,cc.view.getVisibleOrigin().y,cc.view.getVisibleSize().width,this.h);
            this.g1.rect(cc.view.getVisibleOrigin().x,cc.view.getVisibleOrigin().y+cc.view.getVisibleSize().height-this.h,cc.view.getVisibleSize().width,this.h);//
            this.g1.fill();
           //
        }
       
    }
    
    public setTxt(t,l){
        this.txt.string="正在加载素材"+t+"/"+l;
    }
    public killPar(){
        this.g1.clear();
        this.loading.parent=null;
    }
  
}
